package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IBusi;
import com.example.mymatch.model.Busi;
import com.example.mymatch.service.IBusiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：杨滢
 */

@Service
public class IBusiServiceImpl implements IBusiService{
    @Autowired
    private IBusi busiMapper;

    @Override
    public int insertBusi(Busi busi){
        int busiValue=0;
        //查看当前用户名称不能重复
        Busi busi1=new Busi();
        busi1.setBusiName(busi.getBusiName());
        List<Busi> getC=busiMapper.getAllBusi(busi1);
        if (getC.size()>=1){
            //不可以添加用户名称
            busiValue=-1;
        }else {
            busiValue=busiMapper.insertBusi(busi);
        }
        return busiValue;
    }

    @Override
    public List<Busi> getAllBusi(Busi busi){
        return busiMapper.getAllBusi(busi);
    }

    @Override
    public int updateBusi(Busi busi){
        int busiValue=0;
        //判断主键不能为0
        if (busi.getId()!=0){
            //主键信息必修存在
            //名称不能重复
            busiValue=busiMapper.updateBusi(busi);
        }
        return busiValue;
    }

    @Override
    public  int deleteBusi(Busi busi){
        int busiValue=0;
        //判断主键不能为0
        if (busi.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除
            busiValue=busiMapper.deleteBusi(busi);
        }
        return busiValue;
    }

    //单条查询
    @Override
    public Busi getBusi(Busi busi){
        Busi busi1=new Busi();
        if (busi.getId()!=0){
            busi1=busiMapper.getBusi(busi);
        }
        return busi1;
    }
}
